//
//  BVAllAlertTool.m
//  XiangYu
//
//  Created by YYKJ on 2017/6/29.
//  Copyright © 2017年 YYKJ. All rights reserved.
//

#import "BVAllAlertTool.h"
#import "BVAddressModel.h"

@implementation BVAllAlertTool

- (void)fetchAddressCity:(void(^)(NSMutableArray *city))city failure:(void(^)(NSError *error))failure {
    
    NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:[[NSData alloc]initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"address" ofType:@"json"]] options:0 error:nil];
    
    NSMutableArray *arrayM = [NSMutableArray array];
    
    for (NSDictionary *dic in dict[@"citylist"]) {
        BVAddressModel *model = [[BVAddressModel alloc] init];
        model.name = dic[@"n"];
        
        NSMutableArray *cArrayM = [NSMutableArray array];
        for (NSDictionary *cd in dic[@"a"]) {
            BVAddressModel *mm = [[BVAddressModel alloc] init];
            mm.name = cd[@"s"];
            [cArrayM addObject:mm];
        }
        model.cities = cArrayM;
        [arrayM addObject:model];
    }
    city(arrayM);
    
}

- (void)fetchProfessionalSuccess:(void(^)(NSMutableArray *days))success failure:(void(^)(NSError *error))failure {
    
    NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:[[NSData alloc]initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"professional" ofType:@"json"]] options:0 error:nil];
    
    NSMutableArray *arrayM = [NSMutableArray array];
    
    for (NSDictionary *dic in dict[@"list"]) {
        
        BVAddressModel *model = [[BVAddressModel alloc] init];
        model.name = dic[@"p"];
        
        NSMutableArray *cArrayM = [NSMutableArray array];
        for (NSDictionary *cd in dic[@"c"]) {
            
            BVAddressModel *model2 = [[BVAddressModel alloc] init];
            model2.name = cd[@"n"];
            if(!cd[@"a"]){
                model2.cities = [NSMutableArray array];
            }else{
                NSMutableArray *sArrayM = [NSMutableArray array];
                for (NSDictionary *sdict in cd[@"a"]) {
                    BVAddressModel *mm = [[BVAddressModel alloc] init];
                    mm.name = sdict[@"s"];
                    [sArrayM addObject:mm];
                }
                model2.cities = sArrayM;
            }
            [cArrayM addObject:model2];
        }
        model.cities = cArrayM;
        [arrayM addObject:model];
    }
    success(arrayM);
    
}


@end
